import axios from "axios";
export const host: string = `http://localhost:3001`;

// 上传照片
export const uploadPhoto = (data = {}) => {
    return axios.post(`${host}/api/photo/upload`, data, { headers: { 'Content-Type': 'multipart/form-data' } })
        .then(response => response.data)
}
// 删除照片
export const removePhoto = (data = {}) => {
    return axios.post(`${host}/api/photo/delete`, data).then(response => response.data)
}

// 用户注册
export const register = (data = {}) => {
    return axios.post(`${host}/api/user/register`, data).then(response => response.data)
}
// 用户登录
export const login = (data = {}) => {
    return axios.post(`${host}/api/user/login`, data).then(response => response.data)
}
// 检查用户是否已登录
export const logined = (data = {}) => {
    return axios.post(`${host}/api/user/isLogined`, data).then(response => response.data)
}

// 获取当前登录用户的详细信息
export const getCurrentUserDetail = () => {
    const token = localStorage.getItem("AUTO_TOKEN")
    return axios.post(`${host}/api/user/detail2`, {}, { headers: { token } }).then(response => response.data)
}

// 编辑当前用户信息
export const editCurrentUser = (data = {}) => {
    const token = localStorage.getItem("AUTO_TOKEN")
    return axios.post(`${host}/api/user/edit`, data, { headers: { token } }).then(response => response.data)
}

// 获取轮播图列表
export const bannerList = () => {
    return axios.get(`${host}/api/banner/list`).then(response => response.data)
}

// 获取文章列表（分页）
export const articleItems = (data = {}) => {
    return axios.post(`${host}/api/article/items`, data).then(response => response.data)
}

// 获取文章详情
export const articleDetail = (data = {}) => {
    return axios.post(`${host}/api/article/detail`, data).then(response => response.data)
}

// 搜索文章
export const articleSearch = (data = {}) => {
    return axios.post(`${host}/api/article/search`, data).then(response => response.data)
}

// 获取文章列表
export const articleList = (data = {}) => {
    return axios.post(`${host}/api/article/list`, data).then(response => response.data)
}

// 获取分类列表
export const cateList = () => {
    return axios.get(`${host}/api/cate/list`).then(response => response.data)
}

// 获取热门文章列表
export const getHotArticles = (limit = 10) => {
    return axios.get(`${host}/api/article/hot?limit=${limit}`).then(response => response.data)
}

// 获取公开统计数据
export const getPublicStatistics = () => {
    return axios.get(`${host}/api/statistics/public`).then(response => response.data)
}

// 添加评论
export const addComment = (data = {}) => {
    const token = localStorage.getItem("AUTO_TOKEN")
    return axios.post(`${host}/api/comment/add`, data, { headers: { token } }).then(response => response.data)
}

// 获取评论列表
export const getCommentList = (data = {}) => {
    return axios.post(`${host}/api/comment/list`, data).then(response => response.data)
}

// 删除评论
export const deleteComment = (data = {}) => {
    const token = localStorage.getItem("AUTO_TOKEN")
    return axios.post(`${host}/api/comment/delete`, data, { headers: { token } }).then(response => response.data)
}

// 添加收藏
export const addFavorite = (data = {}) => {
    const token = localStorage.getItem("AUTO_TOKEN")
    return axios.post(`${host}/api/favorite/add`, data, { headers: { token } }).then(response => response.data)
}

// 取消收藏
export const removeFavorite = (data = {}) => {
    const token = localStorage.getItem("AUTO_TOKEN")
    return axios.post(`${host}/api/favorite/remove`, data, { headers: { token } }).then(response => response.data)
}

// 检查文章是否已被当前用户收藏
export const checkFavorite = (data = {}) => {
    const token = localStorage.getItem("AUTO_TOKEN")
    return axios.post(`${host}/api/favorite/check`, data, { headers: { token } }).then(response => response.data)
}

// 获取文章的收藏数量
export const getFavoriteCount = (data = {}) => {
    return axios.post(`${host}/api/favorite/count`, data).then(response => response.data)
}

// 获取当前用户的收藏列表
export const getUserFavorites = (data = {}) => {
    const token = localStorage.getItem("AUTO_TOKEN")
    return axios.post(`${host}/api/favorite/user`, data, { headers: { token } }).then(response => response.data)
}

// 添加弹幕
export const addDanmu = (data = {}) => {
    const token = localStorage.getItem("AUTO_TOKEN")
    return axios.post(`${host}/api/danmu/add`, data, { headers: { token } }).then(response => response.data)
}

// 获取所有弹幕
export const getAllDanmus = () => {
    return axios.get(`${host}/api/danmu/all`).then(response => response.data)
}

// 获取弹幕列表（分页）
export const getDanmuList = (data = {}) => {
    return axios.post(`${host}/api/danmu/list`, data).then(response => response.data)
}

// 删除弹幕
export const deleteDanmu = (data = {}) => {
    const token = localStorage.getItem("AUTO_TOKEN")
    return axios.post(`${host}/api/danmu/delete`, data, { headers: { token } }).then(response => response.data)
}